package com.nmsl.statistic.controller;

import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.statistic.mapper.TollManageMapper;
import com.nmsl.statistic.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;

@RestController
@RequestMapping("/patientstats")
public class PatientstatsCpntrollrt {

    @Autowired
    TollManageMapper tollManageMapper;

    @RequestMapping("/age/{date}")
    public AjaxResult age(@PathVariable String date){
        Map<String, Object> map = tollManageMapper.patientAgeDistributed(date);
        if (map == null){
            List<Agestas> list = new ArrayList<>();
            return AjaxResult.success(list);
        }
        Set<String> strings = map.keySet();
        List<Agestas> list = new ArrayList<>();
        strings.forEach(item ->{
            Agestas agestas = new Agestas();
            agestas.setAname(item);
            agestas.setAmount(map.get(item).toString());
            list.add(agestas);
        });
//        Integer.parseInt(strNumber)
//            将list集合中的对象按照Aname由小到大排序
        list.sort((o1, o2) -> {
            Integer i1 = Integer.parseInt(o1.getAname());
            Integer i2 = Integer.parseInt(o2.getAname());
            return i1.compareTo(i2);
        });
        System.out.println(list);
        return AjaxResult.success(list);
    }

    @RequestMapping("/gender/{date}")
    public AjaxResult gender(@PathVariable String date) {
        Map<String, Object> map = tollManageMapper.patientGenderDistributed(date);
        if (map == null) {
            List<GenderStaasVo> list = new ArrayList<>();
            return AjaxResult.success(list);
        }

        Map<String, Object> map1 = new HashMap<>();
//        表数据
        GenderStasTableVo genderStasTableVo = new GenderStasTableVo();
        genderStasTableVo.setFemale(map.get("female_count").toString());
        genderStasTableVo.setMale(map.get("male_count").toString());
        genderStasTableVo.setUnknown(map.get("unknown_count").toString());
        int i = Integer.valueOf(genderStasTableVo.getFemale()).intValue();
        int i1 = Integer.valueOf(genderStasTableVo.getMale()).intValue();
        int i2 = Integer.valueOf(genderStasTableVo.getUnknown()).intValue();
        genderStasTableVo.setAmonut((i+i1+i2)+"");
        map1.put("tablee",genderStasTableVo);
//        echarts 数据
        List< GenderStaasVo> list = new ArrayList<>();
        GenderStaasVo genderStaasVoF = new GenderStaasVo();
        GenderStaasVo genderStaasVoM = new GenderStaasVo();
        GenderStaasVo genderStaasVoU = new GenderStaasVo();
        genderStaasVoF.setName("女");
        genderStaasVoM.setName("男");
        genderStaasVoU.setName("未知");
        genderStaasVoF.setValue(map.get("female_count").toString());
        genderStaasVoM.setValue(map.get("male_count").toString());
        genderStaasVoU.setValue(map.get("unknown_count").toString());
        list.add(genderStaasVoF);
        list.add(genderStaasVoM);
        list.add(genderStaasVoU);
        map1.put("echarts",list);

        return AjaxResult.success(map1);
    }

    @RequestMapping("/matail/{date}")
    public AjaxResult matail(@PathVariable String date){
        Map<String, Object> map = tollManageMapper.patientMaritalDistributed(date);
        if (map == null){
            List<Agestas> list = new ArrayList<>();
            return AjaxResult.success(list);
        }
        Map<String, Object> map1 = new HashMap<>();
//        表数据

        MaritalTabler maritalTabler = new MaritalTabler();
        maritalTabler.setMaritaled(map.get("maritaled").toString());
        maritalTabler.setMarital(map.get("marital").toString());
        maritalTabler.setUnknownMaritaled(map.get("unknown_count").toString());
        int i = Integer.valueOf(maritalTabler.getMarital()).intValue();
        int i1 = Integer.valueOf(maritalTabler.getMaritaled()).intValue();
        int i2 = Integer.valueOf(maritalTabler.getUnknownMaritaled()).intValue();
        maritalTabler.setAmount((i+i1+i2)+"");
        map1.put("tablee",maritalTabler);
//        echarts 数据
        List< GenderStaasVo> list = new ArrayList<>();
        GenderStaasVo genderStaasVoed = new GenderStaasVo();
        GenderStaasVo genderStaasVo = new GenderStaasVo();
        GenderStaasVo genderStaasVoU = new GenderStaasVo();
        genderStaasVoed.setName("已婚");
        genderStaasVo.setName("未婚");
        genderStaasVoU.setName("未知");
        genderStaasVoed.setValue(map.get("maritaled").toString());
        genderStaasVo.setValue(map.get("marital").toString());
        genderStaasVoU.setValue(map.get("unknown_count").toString());
        list.add(genderStaasVoed);
        list.add(genderStaasVo);
        list.add(genderStaasVoU);
        map1.put("echarts",list);
        System.out.println(map1);
        return AjaxResult.success(map1);
    }

    @RequestMapping("/visit/{date}")
    public AjaxResult visit(@PathVariable String date){
        Map<String, Object> map = tollManageMapper.patientVisitDistributed(date);
        System.out.println(map);
        if (map == null){
            List<Agestas> list = new ArrayList<>();
            return AjaxResult.success(list);
        }
        Map<String, Object> map1 = new HashMap<>();
//        表数据
        VistTable vistTable = new VistTable();
        vistTable.setVisted(map.get("visted").toString());
        vistTable.setVist(map.get("vist").toString());
        int i = Integer.valueOf(vistTable.getVist()).intValue();
        int i1 = Integer.valueOf(vistTable.getVisted()).intValue();
        vistTable.setAmunt((i+i1)+"");
        map1.put("tablee",vistTable);
//        echarts 数据
        List< GenderStaasVo> list = new ArrayList<>();
        GenderStaasVo genderStaasVoed = new GenderStaasVo();
        GenderStaasVo genderStaasVo = new GenderStaasVo();
        genderStaasVoed.setName("复诊");
        genderStaasVo.setName("初诊");
        genderStaasVoed.setValue(map.get("visted").toString());
        genderStaasVo.setValue(map.get("vist").toString());
        list.add(genderStaasVo);
        list.add(genderStaasVoed);
        map1.put("echarts",list);

        return AjaxResult.success(map1);
    }
}

